﻿
function main() {
    var testVersion = "(201901021555)版";
    var softwareName = "抖音";
    var view = RequestEngine.getWebView();
    var viewJson = JSON.parse(view);
    var sendMessage = viewJson.sendMessage;
    var issixin=viewJson.issixin;
    var fenSiNum=viewJson.fenSiNum;
    var fanyeNum=viewJson.fanyeNum;
    var waitingTime=viewJson.waitingTime;

    var fenSiNumF=0;

    AccessibilityEngine.sleepEngine(10000);//等待
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) {//更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
    }
    AccessibilityEngine.sleepEngine(2000);//等待
    AccessibilityEngine.mockOnClickIdText(widget.pages.shouye.wode,"我");
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) {//更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/dy");//830 编辑资料最右边的按钮

    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) {//更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
    }
    AccessibilityEngine.sleepEngine(2000);//等待
    AccessibilityEngine.mockOnClickIdText("com.ss.android.ugc.aweme:id/title","通讯录");
	

	
	
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) {//更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
    }
    AccessibilityEngine.sleepEngine(1500);//等待

    for  (var i =0 ; i <fanyeNum; i ++ ){ //翻几页
        ScreenEngine.swipe(parseX(300), parseY(1200), parseX(300), parseY(200), 1500); //从下往上滑动
    }
    showLog("issixin"+issixin);
    while ( fenSiNumF < fenSiNum){
        var mingZiNum= AccessibilityEngine.getIdNum(widget.pages.shousuoyemian.fensiwaimingziliebiao);
        // howLog("mingZiNum"+mingZiNum);
        for  (var i =0 ; i <mingZiNum; i ++ ){ //循环点击名字列表
            AccessibilityEngine.mockOnClickIdIndex(widget.pages.shousuoyemian.fensiwaimingziliebiao,i); // 循环点击名字列表
            AccessibilityEngine.sleepEngine(waitingTime*1000);//等待
            if ( issixin==0 ){
                if (AccessibilityEngine.checkUpId(widget.pages.shousuoyemian.fensiguanzu) == ISTRUE){
                    AccessibilityEngine.mockOnClickId(widget.pages.shousuoyemian.fensiguanzu); // 点击关注
					
					
					
					AccessibilityEngine.sleepEngine(3000);//等待
					if (AccessibilityEngine.checkUpText("对方已设置为私密帐号，需要对方通过请求后才能成功关注哦～") == ISTRUE  || AccessibilityEngine.checkUpIdText("android:id/message", "对方已设置为私密帐号，需要对方通过请求后才能成功关注哦～") == ISTRUE  || AccessibilityEngine.checkUpId("android:id/message") == ISTRUE ) { //私密账号 
						AccessibilityEngine.sleepEngine(2000);
						AccessibilityEngine.mockBack();
						AccessibilityEngine.sleepEngine(2000);
						AccessibilityEngine.mockBack();
						AccessibilityEngine.sleepEngine(2000);
						continue;
					}
					
					AccessibilityEngine.sleepEngine(3000);//等待  //已请求...
					if (AccessibilityEngine.checkUpText("已请求") == ISTRUE  || AccessibilityEngine.checkUpIdText("com.ss.android.ugc.aweme:id/c9g", "已请求") == ISTRUE  || AccessibilityEngine.checkUpId("com.ss.android.ugc.aweme:id/c9g") == ISTRUE ) { //私密账号 
						AccessibilityEngine.sleepEngine(2000);
						AccessibilityEngine.mockBack();
						AccessibilityEngine.sleepEngine(2000);
						AccessibilityEngine.mockBack();
						AccessibilityEngine.sleepEngine(2000);
						continue;
					}
					
					
                    AccessibilityEngine.sleepEngine(2000);//等待
					if (AccessibilityEngine.checkUpId("com.ss.android.ugc.aweme:id/cr0") == ISTRUE) {
                       AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/cr0"); // 取消备注修改
                    }
					AccessibilityEngine.sleepEngine(2000);//等待
                    if (AccessibilityEngine.checkUpId(widget.pages.shousuoyemian.fensiguanzu) == ISTRUE) {
                        AccessibilityEngine.mockOnClickId(widget.pages.shousuoyemian.guanzuyemianfanhui); // 点击返回
                        continue;
                    }
                    fenSiNumF++;
                    if (fenSiNumF >= fenSiNum){
                        showLog("执行成功");
                        setTaskState("5", "脚本执行完毕");
                        throw SyntaxError();
                    }
                }else{				
                    fenSiNumF++;
                    if (fenSiNumF >= fenSiNum){
                        showLog("执行成功");
                        setTaskState("5", "脚本执行完毕");
                        throw SyntaxError();
                    }
				}
                AccessibilityEngine.mockOnClickId(widget.pages.shousuoyemian.guanzuyemianfanhui); // 点击返回
            } else if (issixin==1){
                if (AccessibilityEngine.checkUpId(widget.pages.shousuoyemian.fensiguanzu) == ISTRUE) {
                    AccessibilityEngine.mockOnClickId(widget.pages.shousuoyemian.fensiguanzu); // 点击关注
					AccessibilityEngine.sleepEngine(2000);//等待					
					if (AccessibilityEngine.checkUpId("com.ss.android.ugc.aweme:id/cr0") == ISTRUE) {
                        AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/cr0"); // 取消备注修改
                    }
                    AccessibilityEngine.sleepEngine(2000);//等待
                    if (AccessibilityEngine.checkUpId(widget.pages.shousuoyemian.fensiguanzu) == ISTRUE) {
                        AccessibilityEngine.mockOnClickId(widget.pages.shousuoyemian.guanzuyemianfanhui); // 点击返回
                        continue;
                    }
					AccessibilityEngine.sleepEngine(2000);//等待
                    sendMessageFunction(sendMessage);
                    fenSiNumF++;
                    if (fenSiNumF >= fenSiNum){
                        showLog("执行成功");
                        setTaskState("5", "脚本执行完毕");
                        throw SyntaxError();
                    }
                }else{				
                        showLog("执行成功");
                        setTaskState("5", "脚本执行完毕");
                    
				}
                AccessibilityEngine.mockOnClickId(widget.pages.shousuoyemian.guanzuyemianfanhui); // 点击返回

            }
        }
        if (AccessibilityEngine.checkUpClazzText(widget.classText.widgetByClass.textView, "暂时没有更多了") == ISFALSE) {
            ScreenEngine.swipe(parseX(300), parseY(1200), parseX(300), parseY(200), 1500); //从下往上滑动
        }else {
            showLog("执行成功");
            setTaskState("5", "到底了");
        }
		if (AccessibilityEngine.checkUpClazzText(widget.classText.widgetByClass.textView, "没有更多了") == ISFALSE) {
            ScreenEngine.swipe(parseX(300), parseY(1200), parseX(300), parseY(200), 1500); //从下往上滑动
        }else {
            showLog("执行成功");
            setTaskState("5", "到底了");
        }
    }
}

function sendMessageFunction(sendMessage){
    if (AccessibilityEngine.checkUpId(widget.pages.shousuoyemian.fensisixin) == ISTRUE){
        AccessibilityEngine.sleepEngine(1000);//等待
        if (AccessibilityEngine.checkUpText("取消关注") == ISTRUE) {
            AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/d2q"); // 点击发消息
        }else {
            AccessibilityEngine.mockOnClickId(widget.pages.shousuoyemian.fensisixin); // 点击发消息
        }
        AccessibilityEngine.sleepEngine(3000);//等待
        if (AccessibilityEngine.checkUpClazzText("android:id/button2","取消关注" )== ISTRUE) {
            AccessibilityEngine.mockOnClickClazzText("android:id/button2","取消关注") // 取消关注
        }
        AccessibilityEngine.mockOnClickId(widget.pages.fasongxiaoxi.fasongxiaoxikuang); // 点击发消息框
        AccessibilityEngine.sleepEngine(1000);//等待
        AccessibilityEngine.mockEditId(widget.pages.fasongxiaoxi.fasongxiaoxikuang, sendMessage); //消息框赋值
        AccessibilityEngine.sleepEngine(1000);//等待
        AccessibilityEngine.mockOnClickId(widget.pages.fasongxiaoxi.fasonganniu); // 点击发送按钮
        AccessibilityEngine.mockOnClickId(widget.pages.fasongxiaoxi.fanhui); // 点击返回
    }
}

var publicfunction = RequestEngine.getPluginPath() + "OS_DYCOMMON/publicfunction.js";
include(publicfunction); //公共方法js
var widgetPath = dyConditionCheck();
var widgetbyid = RequestEngine.getPluginPath() +"OS_DYCOMMON/"+ widgetPath;
include(widgetbyid);
main();